$(function () {
    $("#jqGrid").Grid({
        url: '../incomecointask/list',
        colModel: [
            {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
            {label: '用户编号', name: 'userid', index: 'userid', width: 40},
            {label: '用户昵称', name: 'username', index: 'username', width: 50},
            {label: '获取描述', name: 'name', index: 'name', width: 80},
            {label: '所得收益', name: 'integral', index: 'integral', width: 30},
            {
                label: '创建日期', name: 'createdat', index: 'createdAt', width: 80, formatter: function (value) {
                    return transDate(value);
                }
            }]
    });
});

let vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        uid: null,
        data: null,
        dataType: null,
        beginDate: null,
        endDate: null,
        incomecointask: {},
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: '',
            uid: '',
            date: ''

        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.incomecointask = {};
        },
        update: function (event) {
            let id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            let url = vm.incomecointask.id == null ? "../incomecointask/save" : "../incomecointask/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.incomecointask),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            let ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../incomecointask/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../incomecointask/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.incomecointask = r.incomecointask;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name, 'uid': vm.q.uid, 'date': vm.q.date},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: '',
                uid: '',
                date: ''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },

        queryData: function () {
            if(vm.beginDate==null&&vm.endDate!=null){
                alert('开始时间和结束时间必须同时选择');
                return ;
            }
            let params={"uid":vm.uid,"dataType":vm.dataType,"beginDate":vm.beginDate,"endDate":vm.endDate}
            Ajax.request({
                url: "../incomecointask/queryData",
                async: true,
                type: "POST",
                params: params,
                contentType: "application/json",
                successCallback: function (r) {
                    vm.data = r.data;
                }
            });
        },
    }
});